#pragma once


typedef void(*callback)();
static int i = 1;


class thread
{
    void entry()
    {
        cb_();
    }
public:
    thread(callback cb)
        :cb_(cb),isrunning_(false),tid_(0),name_(""),start_time_(0)
    {}


    static void* rouTine(void* args)
    {
        thread* t = static_cast<thread*>(args);
        t->entry();
        return nullptr;
    }

    
    void run()
    {
        name_ = "thread" + std::to_string(i++);
        isrunning_ = true;
        start_time_ = time(nullptr);

        pthread_create(&tid_,nullptr,rouTine,this);
    }

    void join()
    {
        pthread_join(tid_,nullptr);
    }

    std::string name()
    {
        return name_;
    }

    uint64_t threadStartTime()
    {
        return start_time_;
    }

    bool isRunning()
    {
        return isrunning_;
    }

    ~thread()
    {}

private:
    pthread_t tid_;
    std::string name_;

    uint64_t start_time_;
    bool isrunning_;
    callback cb_;

};